package com.walkline.weibo.dao;

import java.util.Vector;
import org.json.me.JSONArray;
import org.json.me.JSONException;
import org.json.me.JSONObject;
import com.walkline.util.Function;
import com.walkline.weibo.WeiboException;
import com.walkline.weibo.WeiboSDK;
import com.walkline.weibo.inf.RepostWrapper;
import com.walkline.weibo.inf.Status;

public class WeiboRepostWrapper extends WeiboObject implements RepostWrapper
{
	private int _total_number = 0;
	private Vector _reposts = new Vector();

	public WeiboRepostWrapper(WeiboSDK weibo, JSONObject jsonObject) throws WeiboException
	{
		super(weibo, jsonObject);

		JSONObject repostWrapper = jsonObject;
		if (repostWrapper != null)
		{
			_total_number = repostWrapper.optInt("total_number");

			JSONArray reposts = repostWrapper.optJSONArray("reposts");
			if (reposts != null)
			{
				JSONObject repostObject;
				Status repost;

				for (int i=0; i<reposts.length(); i++)
				{
					try {
						repostObject = (JSONObject) reposts.get(i);

						repost = new WeiboStatus(weibo, repostObject);
						if (repost != null) {_reposts.addElement(repost);}
					} catch (JSONException e) {Function.errorDialog(e.toString());}
				}
			}
		}
	}

	public int getTotalNumber() {return _total_number;}

	public Vector getReposts() {return _reposts;}
}